package com.sysu.homework.service.Impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.sysu.homework.DAO.HomeworkDAO;
import com.sysu.homework.model.Homework;
import com.sysu.homework.service.HomeworkService;

@Component("homeworkService")
public class HomeworkServiceImpl implements HomeworkService {
	private HomeworkDAO homeworkDAO;

	@Override
	public int addHomework(Homework homework) {
		if (homework != null) {
			return homeworkDAO.save(homework);
		}
		return -1;
	}

	@Resource
	public void setHomeworkDAO(HomeworkDAO homeworkDAO) {
		this.homeworkDAO = homeworkDAO;
	}

	public HomeworkDAO getHomeworkDAO() {
		return homeworkDAO;
	}

	@Override
	public List<Homework> showHomeworks() {
		return homeworkDAO.getHomeworks();
	}

	@Override
	public Homework getHomeworkById(int id) {
		if(id>0){
			return homeworkDAO.getHomeworkById(id);
		}
		return null;
	}

	@Override
	public List<Homework> getUnrankHomeworks() {
		return homeworkDAO.getUnrankHomeworks();
	}

	@Override
	public List<Homework> getUngradeHomeworks() {
		return homeworkDAO.getUnGradeHomeworks();
	}

}
